package com.sywb.chuangyebao.view;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.ManuscriptManagementContract;
import com.sywb.chuangyebao.utils.DoubleFormatUtil;
import com.sywb.chuangyebao.utils.Utils;
import com.sywb.chuangyebao.widget.riseView.RiseNumberTextView;

import org.bining.footstone.rxjava.rxbus.annotation.Subscribe;
import org.bining.footstone.rxjava.rxbus.annotation.Tag;
import org.bining.footstone.rxjava.rxbus.thread.ThreadMode;
import org.bining.footstone.utils.SharedUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class ManuscriptManagementActivity extends ActionbarActivity<ManuscriptManagementContract.Presenter> implements ManuscriptManagementContract.ManuscriptManagementView{
    @BindView(R.id.manuscript_recyclerView)
    RecyclerView manuscriptRecyclerView;
    @BindView(R.id.income_expenditure_tv)
    TextView incomeExpenditureTv;
    @BindView(R.id.account_balance_tv)
    RiseNumberTextView accountBalanceTv;
    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_manuscript_management;
    }
    @Override
    public void initView(Bundle bundle) {
        super.initView(bundle);
        setTitle(R.string.works_management);
    }
    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }
    @Override
    public RecyclerView getRecyclerView() {
        return manuscriptRecyclerView;
    }
    @OnClick({R.id.income_expenditure_tv,R.id.withdraw_tv})
    public void onClick(View view){
       switch (view.getId()){
           case R.id.income_expenditure_tv:
               advance(IncomeExpenditureDetailsActivity.class);
               break;
           case R.id.withdraw_tv:
               if (Utils.checkIsNext(getMyFragmentManager())){
                   advance(WithDrawActivity.class);
               }
               break;
       }
    }
    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_QUERY_BALANCE)})
    public void getBalance(Integer data) {
        animText(accountBalanceTv,Float.parseFloat(DoubleFormatUtil.formatDoubleNumber((double)data)));
        SharedUtils.put(Constants.POST_QUERY_BALANCE,String.valueOf(data));
    }
    @Subscribe(thread = ThreadMode.MAIN_THREAD, tags = {@Tag(Constants.POST_ALIPAY_WEIXIN_WITH_DRAW_INFO)})
    public void updateBalance(String data) {
       mPresenter.queryBalance();
    }
    @Override
    public boolean useRxBus() {
        return true;
    }
    public static void animText(RiseNumberTextView tv, float number) {
        tv.withNumber(number);
        tv.setDuration(1000);
        tv.start();
    }
}
